import {MMKV} from "react-native-mmkv";
import config from "@/config";
import {StateStorage} from 'zustand/middleware';

const appid = config.appid;

export const mmkv = new MMKV({
    id: appid
});

const storage: StateStorage = {
    setItem: (name, value: string | object) => {
        let v = typeof value === "string" ? value : JSON.stringify(value);
        return mmkv.set(name, v);
    },
    getItem: (name) => {
        const value = mmkv.getString(name);
        return value ? value : null;
    },
    removeItem: (name) => {
        return mmkv.delete(name);
    },
}

export default storage;